package ae.pcfc.cldos.online.common.prdb.dao.provider;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

import ae.pcfc.cldos.online.common.dao.GenericDAO;
import ae.pcfc.cldos.online.common.prdb.dao.SystemValuesDAO;
import ae.pcfc.cldos.online.common.prdb.domain.SystemValues;


/**
 * 
 * 
 * @author arosa
 *
 */
public class SystemValuesDAOImpl extends GenericDAO implements SystemValuesDAO {

	@SuppressWarnings("unchecked")
	public List<SystemValues> getSystemValuesByTypeName(String typeName){
		DetachedCriteria criteria = DetachedCriteria.forClass(SystemValues.class);
		criteria.addOrder(Order.asc(SystemValues.__SV_CODE));
		criteria.add(Restrictions.eq(SystemValues.__SV_STATUS, SystemValues.__SV_STATUS_ACTIVE));
		criteria.add(Restrictions.eq(SystemValues.__SV_TYPE, typeName));
		return (List<SystemValues>)getListByCriteria(criteria);
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getTypes(){
		Criteria criteria = getCurrentSession().createCriteria(SystemValues.class);
		criteria.setProjection(Projections.distinct(Projections.property(SystemValues.__SV_TYPE)));
		return (List<String>)criteria.list();
	}
}
